package com.freshfresh.adapter;

import java.util.List;
import java.util.Map;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.freshfresh.activity.R;


public class GuigeAdapter extends BaseAdapter {
	List<Map<String, Object>> apk_list;
	LayoutInflater inflater;
	
	private int clickTemp = 0;
    //标识选择的Item
	public void setSeclection(int position) {
		clickTemp = position;
	}
	
	public GuigeAdapter(Context context, List<Map<String, Object>> apk_list) {
		this.apk_list = apk_list;
		this.inflater = LayoutInflater.from(context);
	}
	

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return apk_list.size();
	}

	public void notifyData(List<Map<String, Object>> apk_list) {
		this.apk_list=apk_list;
		this.notifyDataSetChanged();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return apk_list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@SuppressLint("ResourceAsColor")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Map<String, Object> entity = apk_list.get(position);
		ViewHolderGuige holder;
		if (convertView == null) {
			holder = new ViewHolderGuige();
			convertView = inflater.inflate(R.layout.guige_grid_item, null);
			holder.guige_standard1 = (TextView) convertView
					.findViewById(R.id.guige_standard1);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolderGuige) convertView.getTag();
		}

		if (entity.get("standard2") != null) {
			holder.guige_standard1.setText(entity.get("standard2").toString());
		}
		
		if (clickTemp == position) {
			holder.guige_standard1.setBackgroundResource(R.drawable.button1);
			holder.guige_standard1.setTextColor(Color.WHITE);
			} else{
				holder.guige_standard1.setBackgroundResource(R.drawable.button2);
				holder.guige_standard1.setTextColor(R.color.gray);
			}
		
		


		return convertView;
	}

	class ViewHolderGuige {
		TextView guige_standard1;// 名称

	}
}
